<?php
//including header.php 
include '../../include/header.php';
//including page.php (It is a class which contain functions)
include '../../libraries/page.php';
//created object for page.hp
$page = new page();
//checking the session
session_start();
$userid = $_SESSION['userid'];

//To get current date and time
date_default_timezone_set('Asia/Calcutta');
$date1 = date("Y-m-d H:i:s");

//$user = $_SESSION['username'];
if (!$_SESSION['username']) {
    header("location:../user/login.php");
}
if ($_GET['q'] == 'logout') {
    $page->user_logout();
    header("location:../user/login.php");
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {

    $result = $page->mysql_insert_array("products", $_POST, "submit");
    if ($result) {
        $msg = $message[1];
    } else {
        $msg = $message[0];
    }
}
$products = 'active';
include '../../include/navbar.php';
?>

<div class="bread_crumb" style="margin-left: 2%">
    &laquo;  <a href="products">Back</a>
  </div>
<!----------------------------------Display the result message of Addition--------------------->
<div  align="center"><? echo $msg; ?></div>



<!---------------------------------form------------------------------------------------>
<div class="maindiv">
    <form method="POST"  action="">
        <h3 style="color:#777; text-align: center"> Add Product</h3>
        <div class="leftdiv">
            <label>Product Name</label>
            <input class="input-xlarge" id="focusedInput" type="text" name="name" placeholder="Enter Name..."  required>
        </div>
        <div class="rightdiv"><label>Group</label>
            <select name="groupid" style="width:285px" required> 
                <option></option>
                <?
                //php code to get the data from groups table 
                $groups = mysql_query("select * from groups");
                $id = 0;
                while ($groups_data = mysql_fetch_array($groups)) {

                $group_id = $groups_data['groupid'];
                $name = ucwords(strtolower($groups_data['name']));
                ?>
                <option  value="<? echo $group_id; ?>"><? echo $name; ?></option>
                <?
                }
                ?>
            </select></div>
        <div class="leftdiv">
            <label>Code</label>
            <input class="input-xlarge" id="focusedInput" type="text" name="code" placeholder="Enter code..."  >
        </div>
        <div class="middiv"></div>
        <div class="rightdiv">
            <label>Part No</label>
            <input class="input-xlarge" id="focusedInput" type="text" name="partno" placeholder="Enter part no..."  >
        </div>
        <div class="leftdiv">
            <label>Old Part No</label>
            <input class="input-xlarge" id="focusedInput" type="text" name="oldpartno" placeholder="Enter old part no..."  >
        </div>
        <div class="middiv"></div>
        <div class="rightdiv">
            <label>Packing</label>
            <input class="input-xlarge" id="focusedInput" type="text" name="packing" placeholder="Enter Packing..."  >
        </div>
        <div class="leftdiv">
            <label>Price</label>
            <input class="input-xlarge" id="focusedInput" type="text" name="price" placeholder="Enter Price..."  >
        </div>
        <div class="middiv"></div>
        <div class="rightdiv">
            <label>Opqty</label>
            <input class="input-xlarge" id="focusedInput" type="text" name="opqty" placeholder="Enter opqty..."  >
        </div>
        <div class="leftdiv">
            <label>Active</label>
            <input class="input-xlarge" id="focusedInput" type="text" name="active" readonly value="Y"  >
        </div>
        <div class="middiv"></div>
        <div class="rightdiv">
            <input class="input-xlarge" id="focusedInput" type="hidden" name="c_user" value ="<? echo $userid; ?>"  >
            <input class="input-xlarge" id="focusedInput" type="hidden" name="C_date" value ="<? echo $date1; ?>"  >
            <input class="input-xlarge" id="focusedInput" type="hidden" name="m_user" value ="None"  >
            <input class="input-xlarge" id="focusedInput" type="hidden" name="m_date" value =""  >
        </div>
        <div class="fulldiv">
            <div class="btn1"><button class="btn btn-inverse"  type="submit" name="submit" >Add Product</button></div>
        </div>
    </form>
</div>

<?php
//including footer.php
include '../../include/footer.php';
?>